package com.shyroke.service.serviceImpl;

import java.io.IOException;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shyroke.common.DateUtils;
import com.shyroke.common.JsonConvert;
import com.shyroke.entity.User;
import com.shyroke.entity.XiangCe;
import com.shyroke.mapper.LabelMapper;
import com.shyroke.mapper.XiangCeMapper;
import com.shyroke.service.XiangCeServiceI;

@Service
public class XiangCeServiceImpl implements XiangCeServiceI {

	@Autowired
	private XiangCeMapper xiangceMapper;
	
	@Autowired
	private LabelMapper labelMapper;
	
	@Override
	public void insert(HttpSession session, XiangCe xiangce) throws IOException {
		
		User user=(User)session.getAttribute("user");
		
		JsonConvert.changeUrl("/ueditor/jsp/upload/xiangce/"+user.getUsername()+"/{filename}");
		xiangce.setAuthor(user.getUsername());
		xiangce.setCreateTime(DateUtils.getFormatCurrenDate());
		xiangce.setIsshenhe("否");
		xiangce.setLabelId(labelMapper.selectLabelIdByLabel(xiangce.getLabel()));
		xiangce.setUserid(user.getId());
		xiangceMapper.insert(xiangce);
	
	}
	

}
